﻿Imports DotNetNuke.Common.Utilities.DataCache
Imports DotNetNuke.Entities.Modules

Namespace RTP.ForgottenUser

#Region "ForgottenUserSettings"
    Public Class ForgottenUserSettings
#Region "Private Members"
        Private _allsettings As Hashtable
        Private _moduleID As Integer = -1

        Private _SendAdminID As Boolean = False

#End Region

#Region " Constructors "
        Public Sub New(ByVal ModuleId As Integer)
            _moduleID = ModuleId
            Dim mc As New ModuleController
            _allsettings = mc.GetModuleSettings(_moduleID)

            ReadValue(_allsettings, "SendAdminID", SendAdminID)

        End Sub
#End Region

#Region " Public Methods "

        Public Sub SaveSettings()

            Dim objModules As New ModuleController
            With objModules
                .UpdateModuleSetting(_moduleID, "SendAdminID", Me.SendAdminID.ToString)
            End With
            Dim CacheKey As String = "ForgottenUserSettings" & _moduleID.ToString
            SetCache(CacheKey, Me)

        End Sub

        Public Function GetForgottenUserSettings() As ForgottenUserSettings
            If _moduleID > 0 Then
                Dim CacheKey As String = "ForgottenUserSettings" & _moduleID.ToString
                Dim bs As ForgottenUserSettings = Nothing
                bs = CType(GetCache(CacheKey), ForgottenUserSettings)
                If bs Is Nothing Then
                    bs = New ForgottenUserSettings(_moduleID)
                    SetCache(CacheKey, bs)
                End If
                Return bs
            End If
            Return Nothing
        End Function

#End Region


#Region "Public Properties "
        Public Property SendAdminID() As Boolean
            Get
                Return _SendAdminID
            End Get
            Set(ByVal Value As Boolean)
                _SendAdminID = Value
            End Set
        End Property

#End Region

#Region " Private Methods "

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As String)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), String)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Integer)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Integer)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Boolean)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Boolean)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As System.Web.UI.WebControls.FirstDayOfWeek)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(CInt(ValueTable.Item(ValueName)), System.Web.UI.WebControls.FirstDayOfWeek)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Double)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Double)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Single)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Single)
                Catch ex As Exception
                End Try
            End If
        End Sub

#End Region

    End Class

#End Region
End Namespace
